package com.beesphere.products.throttling;

import java.security.AllPermission;
import java.security.Permission;

public class PermissionChecker {
	
private static final AllPermission ALL_PERMISSION = new AllPermission ();
	
	private static boolean hasAllPermission (SecurityManager sm) {
		try {
		    sm.checkPermission (ALL_PERMISSION);
		    return true;
		} catch (SecurityException se) {
		    return false;
		}
	}
	
	public static void check (Permission perm) {
		SecurityManager sm = System.getSecurityManager ();
		if (sm != null && !hasAllPermission (sm)) {
			sm.checkPermission (perm);
		}
	}

}
